﻿

namespace StateTheaterDataModel
{
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Text;
	using System.Security.Principal;
	using System.Web.Security;


	public partial class StateTheaterDataContext
	{
		public StateTheaterDataContext(ConnectionStringLoader csl)
			: this(csl.ConnectionString)
		{
		}

		private string GetUserName()
		{
			MembershipUser user = Membership.GetUser();
			if (user == null)
				return WindowsIdentity.GetCurrent().Name;
			return user.UserName;
		}

		partial void InsertPeople(People instance)
		{
			instance.ModTime = DateTime.Now;
			instance.ModUser= GetUserName();
			this.ExecuteDynamicInsert(instance);
		}

		partial void UpdatePeople(People instance)
		{
			instance.ModTime = DateTime.Now;
			instance.ModUser = GetUserName();
			this.ExecuteDynamicUpdate(instance);
		}

		partial void InsertVenue(Venue instance)
		{
			instance.ModTime = DateTime.Now;
			instance.ModUser = GetUserName();
			this.ExecuteDynamicInsert(instance);
		}

		partial void UpdateVenue(Venue instance)
		{
			instance.ModTime = DateTime.Now;
			instance.ModUser = GetUserName();
			this.ExecuteDynamicUpdate(instance);
		}

		partial void UpdatePlay(Play instance)
		{
			instance.ModTime = DateTime.Now;
			instance.ModUser = GetUserName();
			this.ExecuteDynamicUpdate(instance);
		}

		partial void InsertPlay(Play instance)
		{
			instance.ModTime = DateTime.Now;
			instance.ModUser = GetUserName();
			this.ExecuteDynamicInsert(instance);
		}


		
		partial void InsertTroupe(Troupe instance)
		{
			instance.ModTime = DateTime.Now;
			instance.ModUser = GetUserName();
			this.ExecuteDynamicInsert(instance);
		}

		partial void UpdateTroupe(Troupe instance)
		{
			instance.ModTime = DateTime.Now;
			instance.ModUser = GetUserName();
			this.ExecuteDynamicUpdate(instance);
		}
		

		partial void UpdateUserAction(UserAction instance)
		{
			instance.ActionTime = DateTime.Now;
			instance.UserName = GetUserName();
			this.ExecuteDynamicUpdate(instance);
		}

		partial void InsertUserAction(UserAction instance)
		{
			instance.ActionTime = DateTime.Now;
			instance.UserName = GetUserName();
			this.ExecuteDynamicInsert(instance);
		}
	}


	public partial class Category //: INotifyPropertyChanging, INotifyPropertyChanged
	{
		public Category(string newCat, string userName)
			: this()
		{
			this.CategoryName = newCat;
			this.ModUser = userName;
			this.ModTime = DateTime.Now;
		}
	}

	public partial class Play
	{
		public string SeoTitle
		{
			get
			{
				return SortTitle.Replace(' ', '-');
			}
		}
	}
}
